import comTitle from "@/views/com/com_title.vue";
import buyingIfor from "./buyingIfor/buyingIfor.vue";
import choiceShop from "./choiceShop.vue";
import { putObj, addObj } from '@/api/shop/procurement.js'
// import { addObj } from "@/api/admin/menu";
export default {
    components: {
        comTitle,
        buyingIfor,
        choiceShop
    },
    data() {
        return {
            labelWidth: "120px",
            disabled: false,
            ruleForm: {
                // beginTime: [],
            },
            rules: {
                beginTime: [
                    { required: true, message: "请选择配送时间", trigger: 'change' },
                ],
            },
            gysmc: [                //供应商名称
            ],
            mendianList: [], //门店list
        }
    },
    mounted() {

        if (this.$route.query.id) {
            this.getInfo(this.$route.query.id)
        }
    },
    methods: {
        getInfo(id) {
            putObj(id).then((val) => {
                this.ruleForm = val.data
                console.log(6667, this.ruleForm)
            })
        },
        submitSave() {   //提交并保存
            // console.log(this.ruleForm)
            // console.log(this.$refs['choiceShop'].ruleForm)
            let obj = { ...this.$refs['buyingIfor'].dataList[0]}
            console.log(Object.assign({}, this.ruleForm, obj))
            console.log(obj.shopPurchaseGoodsList)
            if (this.ruleForm.beginTime) {
                if (obj.shopPurchaseGoodsList.length) {
                    addObj(Object.assign({}, this.ruleForm, obj)).then(() => {
                        this.quxiao('ruleForm')
                    })
                }else{
                    this.$message.warning('请至少选择一种商品')
                }
            } else {
                this.$message.warning('请选择配送日期')
            }
            // this.$refs['ruleForm'].validate((valid) => {
            //     if (valid) {
                   
            //     } else {
            //         console.log('error submit!!');
            //         return false;
            //     }
            // });
        },
        quxiao(ruleForm) {  //取消
            this.$router.go(-1)
            this.$refs[ruleForm].resetFields();
            this.ruleForm = {
                beginTime: [],
            }
        },
        addStore() {
            this.$refs.choiceShop.dialogVisibleTile = '添加直送门店'
            this.$refs.choiceShop.dialogVisible = true
        },
        trigger(data) {
            this.$refs.buyingIfor.dataList = []
            data.chioseVal.forEach(i => {
                this.$refs.buyingIfor.dataList.push({   //将门店push 到采购信息中去
                    mendian: i
                })
            });
        },
        pslxChange(e) {           //总仓还是门店
            this.$refs.buyingIfor.dataList = []
            if (e.target.value == 1) {
                this.$refs.buyingIfor.dataList.push({ loadData: [{}] })
            } else {
                this.$refs.buyingIfor.dataList = []
            }
        },
        cxsjChange(e) {
            this.ruleForm.beginTime = this.formDate(e._d)
            console.log(this.ruleForm)
        }
    },

} 